

function funs(num){
    numtest = num;
}

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init();

            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        table: {
            first: function () {
                // 表格1
                var table1 = $("#table1");
                table1.bootstrapTable({
                    url: 'user/user_level/index',
                    extend: {
                        index_url: 'user/user_level/index' + location.search,
                        add_url: 'user/user_level/add',
                        edit_url: 'user/user_level/edit',
                        del_url: 'user/user_level/del',
                        multi_url: 'user/user_level/multi',
                        table: 'user_level',
                    },
                    toolbar: '#toolbar1',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                            {field: 'name', title: __('Name')},
                            {field: 'buy', title: __('购买T数'), operate:'BETWEEN'},
                            {field: 'direct_push', title: __('直推人数')},
                            {field: 'team_profit', title: __('网体T数'), operate:'BETWEEN'},
                            {field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });

                // 为表格1绑定事件
                Table.api.bindevent(table1);
            },
            second: function () {
                // 表格2
                var table2 = $("#table2");
                table2.bootstrapTable({
                    url: 'user/user_level_rule/index',
                    extend: {
                        index_url: 'user/user_level_rule/index',
                        add_url: 'user/user_level_rule/add',
                        edit_url: 'user/user_level_rule/edit',
                        del_url: 'user/user_level_rule/del',
                        multi_url: 'user/user_level_rule/multi',
                        table: 'user_level_rule',
                    },
                    toolbar: '#toolbar2',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                            {field: 'user_level_id', title: __('用户等级id')},
                            {field: 'user_level_name', title: __('等级名字')},
                            {field: 'team_rate', title: __('社区收益'), operate:'BETWEEN'},
                            {field: 'mining_rate', title: __('挖矿分红'), operate:'BETWEEN'},
                            {field: 'operate', title: __('Operate'), table: table2, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });

                // 为表格2绑定事件
                Table.api.bindevent(table2);
            }
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;

    var Controller1 = {

        //console.log(nums);

        index: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user_level/index' + location.search,
                    add_url: 'user/user_level/add',
                    edit_url: 'user/user_level/edit',
                    del_url: 'user/user_level/del',
                    multi_url: 'user/user_level/multi',
                    table: 'user_level',
                }
            });


            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'buy', title: __('Buy'), operate:'BETWEEN'},
                        {field: 'direct_push', title: __('Direct_push')},
                        {field: 'team_profit', title: __('Team_profit'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },


        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };


    var Controller2 = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user_level_rule/index' + location.search,
                    add_url: 'user/user_level_rule/add',
                    edit_url: 'user/user_level_rule/edit',
                    del_url: 'user/user_level_rule/del',
                    multi_url: 'user/user_level_rule/multi',
                    table: 'user_level_rule',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_level_id', title: __('User_level_id')},
                        {field: 'user_level_name', title: __('等级名字')},
                        // {field: 'direct_push_rate', title: __('Direct_push_rate'), operate:'BETWEEN'},
                        // {field: 'second_push_rate', title: __('Second_push_rate'), operate:'BETWEEN'},
                        // {field: 'level', title: __('Level')},
                        {field: 'team_rate', title: __('Team_rate'), operate:'BETWEEN'},
                        // {field: 'equal_rate', title: __('Equal_rate'), operate:'BETWEEN'},
                        {field: 'mining_rate', title: __('Mining_rate'), operate:'BETWEEN'},
                        // {field: 'equal_mining_rate', title: __('挖矿分红平级收益'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };


    $('#t1').click(function(){
        console.log(1)
        // return Controller1;
    });


    $('#t2').click(function(){
        console.log(2)
        // return Controller2;
        //var nums = 2;
    });


    return Controller2;




});

$(function()
{
    $('#t1').click(function(){

        $.getScript('/assets/js/backend/user/user_fil_rule.js',function(){
            // return Controller1;//这个函数是在new.js里面的，当点击click后运行这个函数
        });
    });
});